/*
https://leetcode.cn/problems/longest-substring-without-repeating-characters/submissions/562526496/
滑动窗口
无重复字符的最长字串
*/

class Solution {
public:
    int lengthOfLongestSubstring(string s) {
        if (s.size() == 0)
            return 0;
        std::vector<int> v(500, -1);
        int ans = 0;
        int left = -1;
        int len = s.size();
        for(int right = 0; right < len; right++)
        {
            left = max(left, v[s[right]]);
            v[s[right]] = right;
            ans = std::max(ans, right - left);
        }
        return ans;
    }
};